package com.hsm.service.impl;

import com.hsm.dao.OrderSettingDao;
import com.hsm.pojo.OrderSetting;
import com.hsm.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {

    @Autowired
    private OrderSettingDao orderSettingDao;

    /**
     * 批量添加
     *
     * @param orderSettingList
     */
    @Override
    public void add(List<OrderSetting> orderSettingList) {
        if (orderSettingList != null && orderSettingList.size() > 0) {
            //1.遍历List<OrderSetting> list
            for (OrderSetting orderSetting : orderSettingList) {
                //2.判断当前的日期之前是否设置过
                int count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
                //2.1 如果设置过, 更新数量
                if(count > 0){
                    orderSettingDao.editNumberByOrderDate(orderSetting);
                }
                //2.2 没有设置过, 保存
                orderSettingDao.add(orderSetting);
            }
        }
    }
}
